package org.example.controller;

import org.example.entity.CourseCollect;
import org.example.entity.Result;
import org.example.service.CourseCollectService;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CourseCollectController
 * @Description TODO
 * @Author qiuye
 * @Date 2025年08月15日 17:18
 * @Version 1.0
 */
@RestController
@RequestMapping("courseCollect")
public class CourseCollectController {
    @Autowired
    private CourseCollectService courseCollectService;
    @GetMapping("{id}")
    public R getCourseCollect(@PathVariable("id") int id) {
        List<CourseCollect> byCourse = courseCollectService.getByCourse(id);
        return R.ok(byCourse);
    }
    @PostMapping("sc/{userId}/{courseId}")
    public R addCollect(@PathVariable("userId") int userId,
                        @PathVariable("courseId") int courseId){
        Result sc = courseCollectService.sc(userId, courseId);
        return R.ok(sc);
    }
    @DeleteMapping("de/{userId}/{courseId}")
    public R deleteCollect( @PathVariable("userId") int userId,
                            @PathVariable("courseId") int courseId){
        Result result = courseCollectService.deleteByUserAndCourse(userId, courseId);
        return R.ok(result);
    }
    @GetMapping("check/{userId}/{courseId}")

    public R checkCollectStatus(@PathVariable("userId") int userId,
                                @PathVariable("courseId") int courseId){
        boolean collected = courseCollectService.isCollected(userId, courseId);
        return R.ok(collected);
    }

}
